package wheel.dataStruct;

import cn.hutool.core.util.RandomUtil;
import lombok.Data;
import wheel.dataStruct.impl.BinaryHeap;

import java.util.Random;

public class BinaryHeapDemo {


    public static void main(String[] args) {
        BinaryHeap<User> binaryHeap = new BinaryHeap<>();

        for(int i=1; i<=10; i++){
            String name = i + "号学生";
            int score = RandomUtil.randomInt(0, 100);
            System.out.println(name + "分数为" + score);
            User user = new User(i+"号学生", score);
            binaryHeap.insert(user);
        }

        System.out.println(binaryHeap.toString());


        User user = null;
        while((user = binaryHeap.poll())!=null){
            System.out.println(user.getScore());
        }
    }



}

@Data
class User implements Comparable{

    private String name;
    private int score;

    public User(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public int compareTo(Object o) {
        User target = (User) o;
        return this.score > target.score ? 1 : -1;
    }
}
